Optimal experimental design 
Matlab code by Maximilian Kasy, 2012

For background, see my paper "Why experimenters might not always want to randomize, and what they could do instead."

If you find errors in the code, please let me know.
If you use this code to pick an optimal treatment assignment, please cite my paper.

******************************************************************

This folder contains the following files:

1) Objective functions for treatment assignment:
VarBetaLinear, VarBetaCK, VarBetaNI

These functions take a treatment assignment vector d as their argument, and return the corresponding objective function value (posterior variance of the ATE)
They also require various global prior variables, as specified in the functions.


2) Weights:
weightsLinear, weightsCK, weightsNI

Similar to 1); return the estimation weights such that betatahat = w' Y


3) discrete Optimization algorithms:
randargminVar, greedyargminVar, simannealargminVar, argminVar

These take as an argument a function handle, referring to either of the objective functions of 1).
They return the posterior-variance minimizing treatment assignment, and store the minimal variance in Vstar.
Recommended use is to just call argminVar, which evokes the other algorithms.

4) setting prior parameters:
setparameters 

This script sets prior parameters.


******************************************************************

Example use:

global X n dimx Vstar
%%%input X
[n, dimx]=size(X); 
vbeta = @VarBetaNI  
weights = @weightsNI 
setparameters 
Dstar=argminVar(vbeta);
w=weights(Dstar)
csvwrite('optimaldesign.csv',[Dstar(:), w(:), X])

